<template>
  <div class="panel-container">
    <ForgetHeadbar :title="title" />
    <div class="panel-steps">
      <el-steps :active="active" status="true" align-center>
        <el-step title="验证身份"></el-step>
        <el-step title="绑定新手机"></el-step>
        <el-step title="完成"></el-step>
      </el-steps>
    </div>
    <div class="panel-changeBindTel">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">

        <el-form-item label="手机号码：" v-if="active==1">
          <div class="step-1"><span>{{ phone }}</span>为了保证您的账号安全，请验证身份，验证成功后才能换绑手机。</div>
        </el-form-item>

        <el-form-item label="手机号码：" prop="tel" v-if="active==2">
          <el-input placeholder="请输入新手机号码" v-model="ruleForm.tel" @change="changeNewTel" maxlength="11" style="width:320px;"></el-input>
        </el-form-item>

       <!--  <div class="bind-wechat" v-if="active==2">
          <div class="qrcode">
            <img src="https://dummyimage.com/210x210/00405d/FFF&text=qrcode" />
          </div>
          <p>请打开要绑定的微信，扫一扫扫描上方二维码，即可完成绑定</p>
        </div> -->

        <el-form-item label="手机验证码：" prop="code" v-if="active == 1">
          <el-input placeholder="请输入验证码" v-model="ruleForm.code1" style="width:174px; margin-right:10px"></el-input>
          <GetVcode1 @vcodeCallback="sendVcodeSuccess" />
        </el-form-item>

        <el-form-item label="手机验证码：" prop="code" v-else-if="active == 2">
          <el-input placeholder="请输入验证码" v-model="ruleForm.code2" style="width:174px; margin-right:10px"></el-input>
          <GetVcode2 ref="GetVcode2" @vcodeCallback="sendVcodeSuccess" />
        </el-form-item>
        <el-form-item v-if="active<3">
          <el-button type="primary" @click="submitForm('ruleForm')" style="width:320px;">下一步</el-button>
        </el-form-item>

        <div class="panel-changeSuccess" v-if="active==3">
          <div class="tips"><svg-icon icon-class="correct" class="correct" />恭喜您，手机修改成功</div>
          <el-button type="primary" @click="outLogin()">重新登录</el-button>
        </div>

      </el-form>
    </div>

    <div class="panel-changeBindTips">
      <h5>没收到短信验证码？</h5>
      <div class="text">
        1、网络通讯异常可能会造成短信丢失，请重新获取或稍后再试。<br/>
        2、请核实手机是否已欠费停机，或者屏蔽了系统短信。<br/>
        3、如果手机已丢失或停用， 请选择其他验证方式 。<br/>
        4、您也可以尝试将SIM卡移动到另一部手机，然后重试。
      </div>
    </div>
  </div>
</template>

<script>


import ForgetHeadbar from '@/components/Forget/header'
import GetVcode1 from '@/components/GetVcode/updatePhoneNumber'
import GetVcode2 from '@/components/GetVcode/bindingNewPhone'
import { getCheckCode } from '@/api/others'
import { getNewCheckCode } from '@/api/others'
import { removeToken, removeAuthUserInfo } from '@/utils/auth'
export default {
  name: 'ChangeBindTel',
  components: {
    ForgetHeadbar,
    GetVcode1,
    GetVcode2
  },
  data() {
    return{
      title: '更换手机',
      active: 1,
      phone: this.getUrlParams('phone'),
      ruleForm: {
        transactionNo: '',
        transactionDateStart: '',
        transactionDateEnd: '',
        transactionType: '',
        code1: '',
        code2: '',
      },
      rules: {
        tel: [
          { required: true, trigger: 'blur', message: '请输入新手机号码' }
        ],
        code1: [
          { required: true, message: '请输入验证码', trigger: 'blur' }
        ],
        code2: [
          { required: true, message: '请输入验证码', trigger: 'blur' }
        ]
      },
    }
  },
  methods: {
    submitForm(formName) {
      if(this.active == 1){
        getCheckCode({
          code: this.ruleForm.code1,
          mobile: this.phone,
        }).then(res=>{
          if(res.code == 200){
            this.active = 2
          }else{
            this.actionsAfter(res.msg, 'error')
          }
        })
      }else if(this.active == 2){
        getNewCheckCode({
          code: this.ruleForm.code2,
          mobile: this.ruleForm.tel,
          userId: this.userId
        }).then(res=>{
          if(res.code == 200){
            this.active = 3
          }else{
            this.actionsAfter(res.msg, 'error')
          }
        })
      }
      // this.active += 1;
      // this.$refs[formName].validate((valid) => {
      //   if (valid) {
      //     console.log('submit!');
      //   } else {
      //     console.log('error submit!!');
      //     return false;
      //   }
      // });
    },
    //
    sendVcodeSuccess() {

    },
    //
    changeNewTel(val) {
      this.$refs.GetVcode2.getNewTel(val);
      // getNewCheckCode({
      //   code: this.ruleForm.code2,
      //   mobile: this.ruleForm.tel,
      //   userId: this.userId
      //   }).then(res=>{
      //     if (res.code == 200) {
      //       if (!res.data) {
      //         callback(new Error('云工厂名称不能重复'))
      //       } else {
      //         callback()
      //       }
      //     }
      //   })
    },
    outLogin() {
      removeToken();
      removeAuthUserInfo();
      window.location.href = '/mallplus/login'
    }
  }
}
</script>

<style lang="scss">
  .panel-container{
    min-height: 100vh;
    background: #fff;
  }
  .panel-steps{
    width: 900px;
    margin: 40px auto;
  }
  .el-step__title{
    font-size: 14px;
  }
  .el-step__title.is-process{
    font-weight: 300;
    color: #c0c4cc;
  }
  .el-step__head.is-process{
    color: #c0c4cc;
    border-color: #c0c4cc;
  }
  .panel-changeBindTel{
    width: 700px;
    padding-left: 50px;
    margin: auto;
    .el-form-item{
      margin-bottom: 34px;
    }
    .step-1{
      color: #858383;
      font-size: 14px;
      span{
        color: red;
        margin-right: 20px;
      }
    }
  }
  .panel-changeBindTips{
    width: 760px;
    padding: 16px 20px;
    margin: 60px auto 30px;
    border: 1px solid #FFC7C7;
    color: #858383;
    background: #FFF4F4;
    font-size: 12px;
    line-height: 26px;
    h5{
      margin: 0;
      font-weight: 300;
      color: #646161;
    }
  }
  .panel-changeSuccess{
    margin-left: -50px;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    line-height: 40px;
    color: #00AA03;
    .tips{
      margin-bottom: 20px;
    }
    .correct{
      font-size: 26px;
      display: inline-block;
      vertical-align: top;
      margin: 5px 10px 0 0;
    }
  }
  .bind-wechat{
    text-align: center;
    .qrcode{
      width: 230px;
      height: 230px;
      padding: 10px;
      margin: auto;
      border: 1px solid #eee;
    }
    p{
      font-size: 13px;
      color: #666;
      padding: 10px 0;
    }
  }
</style>
